package org.swift.mashup.engine.model;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Map;

@SuppressWarnings({"unchecked","rawtypes"})
public class ActivityResultItem extends ActivityResultComponent {

	protected final Object output;

	public ActivityResultItem(final Object output) {
		this.output = output;
	}

	public ActivityResultItem(final String type, final Object output) {
		this.output = output;
		setType(type);
	}

	@Override
	public void updateOutputMap(final Map<String, Collection> outputs,
			final String defaultType) {
		if (this.type == null) {
			this.type = defaultType;
		}
		if (outputs.containsKey(type)) {
			outputs.get(type).add(output);
		} else {
			Collection<Object> resultHolder = new ArrayList<Object>();
			resultHolder.add(output);
			outputs.put(type, resultHolder);
		}
	}

	@Override
	public Object getOutput() {
		return output;
	}

	protected boolean invalidType() {
		return (type == null || type.trim().length() == 0);
	}
}
